﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action.Terran
{
	public class ActionProducePlanetaryFortress : ActionProduceTerran
	{
		public static ActionProducePlanetaryFortress Instance = new ActionProducePlanetaryFortress();

		private ActionProducePlanetaryFortress() : base(50, 150, 150, 0) { }

		public override int AvailableProducer(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return (state.CommandCenter.AvailableForProduction);
		}

		public override bool HaveResources(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return base.HaveResources(bo) && state.CommandCenter.Count > 0;
		}

		public override bool IsInvalid(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return base.IsInvalid(bo) || state.CommandCenter.Count == 0 || state.EngineeringBay.Count == 0;
		}

		public override bool HaveTechnology(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			return state.Barracks.Count + state.BarracksReactor.Count + state.BarracksTechLab.Count > 0 &&
				state.EngineeringBay.Count > 0;
		}

		public void OnProductionFinished(IBuildOrder bo)
		{
			TerranState state = bo.State as TerranState;
			state.CommandCenter.Count--;
			state.PlanetaryFortress.Count++;
		}

		public override void Execute(IBuildOrder bo)
		{
			base.Execute(bo);
			TerranState state = bo.State as TerranState;
			state.CommandCenter.Production++;
			bo.AddAction(state.Time + BuildTime, new ActionGeneric("ActionSpawnPlanetaryFortress", (ActionGeneric.ActionExecuteDelegate)delegate(IBuildOrder ibo)
			{
				TerranState ibostate = ibo.State as TerranState;
				ibostate.CommandCenter.Production--;
				OnProductionFinished(ibo);
			}));
		}

		private IAction[,] m_Requirements;
		public override IAction[,] Requirements
		{
			get
			{
				if (m_Requirements == null)
					m_Requirements = new IAction[,] { { ActionProduceRefinery.Instance, ActionProduceEngineeringBay.Instance } };
				return m_Requirements;
			}
		}

		private IAction[,] m_Inputs;
		public override IAction[,] Inputs
		{
			get
			{
				if (m_Inputs == null)
					m_Inputs = new IAction[,] { { ActionProduceCommandCenter.Instance } };
				return m_Inputs;
			}
		}
	}
}
